<template>
  <Layout>
    <SliderContent
      :slider-title="$t('NewsCategory')"
      :content-nav="$t('NewsCenter') + ' > ' + curNav.name"
    >
      <template #slider>
        <Menu :data="category"></Menu>
      </template>
      <template #content>
        <ul>
          <li v-for="item in newsList" :key="item.id">
            <a class="news-item" :href="'/news/detail?id=' + item.id">
              <DoubleRightOutlined class="icon" />
              <h3>{{ item.name }}</h3>
            </a>
          </li>
        </ul>
        <div class="pagination" v-if="newsList.length">
          <a-pagination
            v-model:current="curPage"
            show-quick-jumper
            :total="50"
            @change="handleChangePage"
            :show-total="(total) => $t('TotalItems', { total: total })"
          />
        </div>
      </template>
    </SliderContent>
  </Layout>
</template>

<script setup>
import Layout from "@/components/Layout.vue";
import SliderContent from "@/components/SliderContent.vue";
import Menu from "@/components/Menu.vue";
import { onBeforeMount, ref } from "vue";
import { DoubleRightOutlined } from "@ant-design/icons-vue";
import { getClassify, getArticleList } from "@/api/news";
const curPage = ref(1);
const curNav = ref({});
const category = ref([]);
const newsList = ref([]);

onBeforeMount(() => {
  getClassify().then((res) => {
    category.value = res.data;
    if (res.data && res.data.length > 0) {
      handleClickItem(res.data[0]);
    }
  });
});

const handleClickItem = (classify) => {
  curNav.value = classify;
  handleGetList();
};

const handleChangePage = (page, pageSize) => {
  curPage.value = page;
  handleGetList();
};

const handleGetList = () => {
  getArticleList({
    bid: 0,
    cid: curNav.value.id,
    pagenum: curPage.value,
    keyword: "",
  }).then((res) => {
    newsList.value = res.data || [];
  });
};
</script>

<style lang="less">
.category-list {
  text-align: center;
  .category-item {
    display: block;
    padding: 6px 2px;
    color: rgba(51, 51, 51, 0.88);
    line-height: 1.5;
    font-size: 7px;
    text-decoration: none;
  }
}

.news-item {
  display: flex;
  align-items: center;
  padding: 7px 0;
  text-decoration: none;
  // prettier-ignore
  border-bottom: 1PX solid #e5e5e5;
  .icon {
    color: #aaaaaa;
    font-size: 5px;
    margin-right: 2px;
  }
  h3 {
    flex: 1;
    width: 0;
    padding-right: 7px;
    color: #1a1a1a;
    font-weight: 500;
    font-size: 7px;
  }
}
.pagination {
  text-align: right;
  margin-top: 34px;
}
</style>
